
	//sqlite operation
	var State_Code = {1:"sucess",2:"database exception"};
	var db = openDatabase("loc","1.0","local data",2 * 1024 * 1024);
	var DB = {
		createTable : function () {
			db.transaction(function(tx) {
				tx.executeSql("Create TABLE if not exists location(id INTEGER PRIMARY KEY,username UNIQUE,password,longitude,altitude,logintime)");
			});
		},
	  	deleteTable : function(){
	  		db.transaction(function(tx) {
	  			tx.executeSql("drop TABLE if exists location",
	  					       [],
	  						   function(tx,re) {
							       alert("deleted table success");
							   },
							   function(tx,error) {
								   alert("deleted table fail:"+error.message);
							   }
				);
	  		});
	  	},
	  	//query data by username
  		queryDataByUserName : function(username) {
  			db.transaction(function(tx) {
  				tx.executeSql("select * from location where username = ?",
  							   [username],
  							   function(tx,rs) {
  									var data = "";
				  					for (var i = 0; i < rs.rows.length; i++) {
				  						var value = rs.rows.item(i);
				  						//convert the object to string
				  						data = JSON.stringify(value);
				  					}
				  					//show the result
				  					showAllData(data);
  								}
  				);
  			});
  		},
  		//insert the data
  		//data ["zhangsan","123123",116.407413,39.904214,"2012-4-3"]
  		addData : function(data) {
  			db.transaction(function(tx) {
  				tx.executeSql("insert into location(username,password,longitude,altitude,logintime) values(?,?,?,?)",
  							   data,
  							   function(tx,re) {
  							       alert("save success");
  							   },
  							   function(tx,error) {
  								   alert("save fail:"+error.message);
  							   }
  				);
  			});
  		}
	};
	//output the data
	function showAllData(value) {
		alert(value);
	}
